// Written by Marco, modified by Flame
Class FAllyBot extends FBot;

function FindBetterTarget()
{
	local Controller C;
	//local KFMonster P,BP;
	local KFHumanPawn P,BP;
	//local float Cost,Best;

	for( C=Level.ControllerList; C!=None; C=C.nextController )
	{
		P = KFHumanPawn(C.Pawn);
		if( P==None || FEnemyBot(C)==None )
			continue;
		BP=P;
		
		Enemy=BP;
		Target=BP;
		//Log(PlayerReplicationInfo.PlayerName@"FindBetterTarget"@Enemy@Enemy.PlayerReplicationInfo.PlayerName);
		break;
/* 		P = KFMonster(C.Pawn);
		if( P==None || P.Health<=0 || !LineOfSightTo(P) || P.bDecapitated )
			continue;
		Cost = GetEnemyDesire(P,true);
		if( BP==None || Best>Cost )
		{
			BP = P;
			Best = Cost;
		} */
	}
/* 	if( BP!=None && BP!=Enemy )
	{
		Enemy = BP;
		Target = BP;
	} */
}

function bool SetEnemy( Pawn NewEnemy )
{
	if(KFHumanPawn(NewEnemy)==None || FEnemyBot(NewEnemy.Controller)==None)
		return false;
	//KFHumanPawn(Pawn).CreateInventoryVeterancy("KFMod.M14EBRBattleRifle", 1);
	//RemoveItemFromInv(Pawn,"KFMod.Single");
	//RemoveItemFromInv(Pawn,"KFMod.Knife");
	//KFHumanPawn(Pawn).CreateInventoryVeterancy("PerksSimHostOrg.LawW", 0.1);
	//Log(PlayerReplicationInfo.PlayerName@"NewEnemy"@NewEnemy@FBot(NewEnemy.Controller)!=None);
	//if( KFMonster(NewEnemy)==None || 
//		NewEnemy.Health<=0 || 
	//	(Enemy!=None && GetEnemyDesire(KFMonster(Enemy),false)<GetEnemyDesire(KFMonster(NewEnemy),false)) )
		//return false;
	Enemy = NewEnemy;
	EnemyChanged(LineOfSightTo(Enemy));
/* 	if( Mut.NextYellTime<Level.TimeSeconds && FRand()<0.1f )
	{
		SendMessage(None, 'INSULT', 0, 5, ''); // Insult Specimen
		Mut.NextYellTime = Level.TimeSeconds+20.f+20.f*FRand();
	} */
	return true;
}

function bool FindInjuredAlly()
{
	local controller c;
	local KFHumanPawn aKFHPawn;
	local float AllyDist;
	local float BestDist;
	local bool bGoMedGun;
	local vector Dummy;
	local Actor A;

	InjuredAlly = None;
	if( ManyEnemiesAround(Pawn.Location) )
		return false;
	if( FindMedGun() && MyMedGun.ChargeBar()>0.49f )
		bGoMedGun = true;
	else if( FindMySyringe()==none || MySyringe.ChargeBar()<0.6f )
		return false;

	for( c=level.ControllerList; c!=none; c=c.nextController )
	{
		if( C==Self )
			continue;

		aKFHPawn = KFHumanPawn(c.pawn);

		// If he's dead. dont bother.
		if(	aKFHPawn==none || aKFHPawn.Health<=0 || aKFHPawn.Health>70 || 
			VSizeSquared(aKFHPawn.Location-Pawn.Location)>1000000.f ||
			FEnemyBot(C)!=None
			)
			continue;

		if( bGoMedGun )
		{
			A = Pawn.Trace(Dummy,Dummy,aKFHPawn.Location,Pawn.Location,true);
			if( A!=None && A!=aKFHPawn && A.Owner!=aKFHPawn )
				continue;
		}
		else if( !ActorReachable(aKFHPawn) )
			continue;
		AllyDist = VSizeSquared(Pawn.Location - aKFHPawn.Location);
		if( AKFHPawn.Health<40 )
			AllyDist*=0.5f;
		if( InjuredAlly==none || (AllyDist<BestDist) )
		{
			InjuredAlly = aKFHPawn;
			BestDist = AllyDist;
		}
	}
	if( !bGoMedGun && InjuredAlly!=None && ManyEnemiesAround(InjuredAlly.Location) )
		InjuredAlly = None;
/* 	if( InjuredAlly!=None )
	{
		if( FBot(InjuredAlly.Controller)!=None )
			FBot(InjuredAlly.Controller).SendMessage(None, 'SUPPORT', Rand(2), 4.f, '');
		return true;
	} */
	return false;
}

defaultproperties
{
}
